from flask import Flask, jsonify, request, Blueprint

app = Flask(__name__)
note_bp = Blueprint('note', __name__)


@note_bp.route('/api/notes', methods=['POST'])
def create_note():
    # return jsonify({'message': 'Note created successfully'}), 201
    # print("1")
    from service.NoteService import create_note
    result = create_note()
    print(result)
    return jsonify(result)


@note_bp.route('/api/notes/<note_id>', methods=['DELETE'])
def delete_note(note_id):
    from service.NoteService import delete_note
    result = delete_note(note_id)
    print(result)
    return jsonify(result)

@note_bp.route('/api/notes/<note_id>', methods=['PUT'])
def update_note(note_id):
    from service.NoteService import update_note
    result = update_note(note_id)
    print(result)
    return jsonify(result)

@note_bp.route('/api/notes/<note_id>', methods=['GET'])
def get_note(note_id):
    from service.NoteService import get_note
    result = get_note(note_id)
    print(result)
    return jsonify(result)

@note_bp.route('/books/notes', methods=['GET'])
def get_notes():
    from service.NoteService import get_notes
    page_num = request.args.get('page_num',1,type=int)
    page_size = request.args.get('page_size',10,type=int)
    order_by = request.args.get('order_by',None)
    user_id = request.args.get('user_id',None)
    isbn = request.args.get('isbn',None)
    content_keyword = request.args.get('content_keyword',None)
    result = get_notes(page_num,page_size,order_by,user_id,isbn,content_keyword)
    print(result)
    return jsonify(result)

@note_bp.route('/api/notes/<note_id>/like', methods=['POST'])
def note_like(note_id):
    from service.NoteService import note_like
    result = note_like(note_id)
    print(result)
    return jsonify(result)

@note_bp.route('/api/notes/<note_id>/collect', methods=['POST'])
def note_collect(note_id):
    from service.NoteService import note_collect
    result = note_collect(note_id)
    print(result)
    return jsonify(result)

@note_bp.route('/api/notes/<note_id>',methods=['POST'])
def note_transmit(note_id):
    from service.NoteService import note_transmit
    result = note_transmit(note_id)
    print(result)
    return jsonify(result)